using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Diagnostics;
using System.Windows.Ink;

namespace WozLib.UI.Ink.Adorners
{
  public class StrokeSelectionPreviewAdorner : Adorner
  {
    private Stroke _SelectingStroke;

    public Stroke SelectingStroke
    {
      get { return _SelectingStroke; }
      set { _SelectingStroke = value; }
    }


    // Be sure to call the base class constructor.
    public StrokeSelectionPreviewAdorner(UIElement adornedElement, Stroke selectingStroke)
      : base(adornedElement)
    {
      SelectingStroke = selectingStroke;
    }

    protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
    {
      return null;
    }

    protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
    {
      return null;
    }

    // A common way to implement an adorner's rendering behavior is to override the OnRender
    // method, which is called by the layout subsystem as part of a rendering pass.
    protected override void OnRender(DrawingContext drawingContext)
    {

      try
      {
        // could also get the beziercurve points or whatever to outline it a little closer
        Rect adornedElementRect = SelectingStroke.GetBounds();

        Rect adornedElementRectInner = new Rect(adornedElementRect.X + 5.0,
          adornedElementRect.Y + 5.0, adornedElementRect.Width - 10.0, 
          adornedElementRect.Height - 10.0);



        SolidColorBrush brush = new SolidColorBrush(Colors.Black);
        brush.Opacity = 0.30;

        Pen pen = new Pen(brush, 5.0);



        SolidColorBrush brush2 = new SolidColorBrush(Colors.White);
        brush2.Opacity = 0.30;

        Pen pen2 = new Pen(brush2, 5.0);



        drawingContext.DrawRectangle(Brushes.Transparent, pen, adornedElementRect);

        drawingContext.DrawRectangle(Brushes.Transparent, pen2, adornedElementRectInner);

      }
      catch (Exception ex)
      {
        Debug.WriteLine(ex.ToString());
      }
    }
  }
}
